package org.example.spring_boot_blog.common.pojo;

import lombok.Data;
import org.example.spring_boot_blog.common.enums.ResultStatusEnum;

@Data
public class Result <T>{
    private int code;
    private String errMsg;
    private T data;
    public static<T> Result<T> ok(T data){
        Result result=new Result();
        result.setCode(ResultStatusEnum.SUCCESS.getCode());
        result.setErrMsg("");
        result.setData(data);
        return result;
    }
    public static<T> Result<T> fail(String errMsg){
        Result result=new Result();
        result.setCode(ResultStatusEnum.FAIL.getCode());
        result.setErrMsg(errMsg);

        return result;
    }
    public static<T> Result<T> fail(String errMsg,T data){
        Result result=new Result();
        result.setCode(ResultStatusEnum.FAIL.getCode());
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }
}
